package com.example.wanglei.myapplication;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.webkit.WebView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

import com.example.wanglei.myapplication.PostUtils;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class DetailActivity extends AppCompatActivity {

    private String result = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);

//        final Button button = (Button) findViewById(R.id.btn);

        final WebView webview = (WebView) findViewById(R.id.webview);

        /*获取Intent中的Bundle对象*/
        Bundle bundle = this.getIntent().getExtras();

        /*获取Bundle中的数据，注意类型和key*/
        final String news_no = bundle.getString("news_no");

        new Thread() {
            public void run() {
                result = PostUtils.LoginByPost("http://47.97.107.221:8080/cland-websiteFront/news/queryNewsDetail.htm?iType=2&sNewsNo=" + news_no);
//                handler.handleMessage(result);

                //更新主线程UI
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {

                        /**
                         //             * 这里需要分析服务器回传的json格式数据，
                         //             */

                        try {
                            JSONObject jsonObject = new JSONObject(result).getJSONObject("newsInfo");
                            String content = jsonObject.getString("sNewContent");

//                            button.setText(content);

                            webview.loadDataWithBaseURL(null,content, "text/html" , "utf-8", null);

                        } catch (Exception e) {
//                            Log.e("tag", e.toString());
                        }

                    }
                });
            };

        }.start();
    }

}
